#include "bfoodemo.h"
#include <iostream>

using namespace std;

BFooDemo::BFooDemo()
    : id (0)
    , id2(nullptr)
{
    cout << "default ctor, this =" << this << endl;
    id2 = new int(5);
}

BFooDemo::BFooDemo(int n)
    : id (n)
    , id2(nullptr)
{
    cout << "ctor, this =" << this << endl;
    id2 = new int(4);
}

BFooDemo::~BFooDemo()
{
    cout << "default dtor, this =" << this << " id = " << id  /*<< " id2 = "<< *id2*/ << endl;
    if (id2 != nullptr)
    {
        delete id2;
        id2 = nullptr;
    }
}

void *BFooDemo::operator new(size_t nsize)
{
    cout << "lm member new, the size is " << nsize << endl;
    BFooDemo *p = (BFooDemo*)malloc(nsize);
    return p;
}

void *BFooDemo::operator new(size_t size, void *start)
{
    cout << "lm member new with void *, the size is " << size << endl;
    return start;
}

void *BFooDemo::operator new(size_t size, long extra)
{
    cout << "lm member new with extra, the size is " << size << endl;
    return malloc(size + extra);
}

void *BFooDemo::operator new(size_t size, long extra, char init)
{
    cout << "lm member new with extra and init, the size is " << size << endl;
    return malloc(size + extra);
}
